<?php
// Modify this
$recipients = "your@email.com";
$host = "smtp.gmail.com"; //if you dont use GMail, modify to your needs
$password = "yourpassword";
$name = "Your name";
$fail = "Server: ".$argv[2]." is offline";
$success = "Server ".$argv[2]." is online";
$reporttitle = "Report: main server";
$body = "Blank this if you dont want body message (except reports)";
// Stop modifying!

require_once "Mail.php";
$from = $name." <".$recipients.">";
$to = $name." <".$recipients.">";
switch ($argv[1])
{
case 0:
$subject = $success;
break;
case 1:
$subject = $fail;
break;
case 2:
$subject = $reporttitle;

exec("uptime",$uptime);
if ($end=strpos($uptime[0], ',')) {
$text[0] = substr($uptime[0], 0, $end);
}
else
echo "Error getting uptime";
exec("uptime",$load);
if ($start=strpos($load[0], 'age:')) {
$end=strlen($load[0])-$start;
$text[1] = substr($load[0], $start+5, $end);
unset ($a);
}
else
echo "Error getting load";
exec("df -h",$a);
if ($start=strpos($a[1], '%')) {
$text[2] = substr($a[1], $start-2, 3);
unset ($a);
}
else
echo 'Error getting HDD space';
$body = "Uptime: ".$text[0]."\nLoad: ".$text[1]."\nHDD Space: ".$text[2];
break;

default:
$subject = "Error undefined";
break;
}


$username = $recipients;
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} 
?>